package sugarbind_input

class Author {

    String title
	String last_Name
	String first_Name
	String mid_Name
	String suffix
	String url

    static constraints = {
		title(nullable:true)
		last_Name(blank:false)
		first_Name(nullable:true)
		mid_Name(nullable:true)
		suffix(nullable:true)
		
		author_Articles(nullable:true)
		url(nullable:true)
		
		last_Name(unique:['first_Name'])
//		last_Name(unique:['mid_Name'])
		
	}
	
	static hasMany = [author_Articles:Author_Article]
	
	static mapping = {
//		id column: 'author_id'
		id generator: 'sequence', params: [sequence: 'author_id_seq']
	}
	
	public String toString(){
		def name = last_Name + " " + first_Name
//		if(mid_Name != null)
//		{
//			name += " " mid_Name
//		}
		name += " (" + id + ")"
		return name
	}
	
	public static listAuthors()
	{
		Author.list().sort{ it.toString(); }
	}
}
